﻿@inherits MudFormComponent<T, string>

@typeparam T
@namespace MudBlazor
@using Microsoft.AspNetCore.Components.Forms
@using MudBlazor.Interfaces

@{
#pragma warning disable CS0618 // Type or member is obsolete
}

<MudInputControl Class="@Classname" Style="@Style" Error="HasErrors" ErrorText="@GetErrorText()" Required="@Required">
    <InputContent>
        @for (var index = 1; index <= _numberOfActiveFileInputs; index++)
        {
            var localIndex = index;
            <InputFile @key="@localIndex"
                       OnChange="OnChangeAsync"
                       class="@GetInputClass(localIndex)"
                       style="@InputStyle"
                       hidden="@(Hidden ? "" : null)"
                       multiple="@(typeof(T) == typeof(IReadOnlyList<IBrowserFile>) ? "" : null)"
                       accept="@Accept"
                       disabled="@(GetDisabledState())"
                       @attributes="UserAttributes"
                       id="@GetInputId(localIndex)"
                       required="@Required"
                       aria-required="@Required.ToString().ToLowerInvariant()" />
        }
        @if (ActivatorContent != null)
        {
            <CascadingValue Value="@((IActivatable)this)"
                            IsFixed="true">
                <CascadingValue Name="ParentDisabled"
                                Value="GetDisabledState()">
                    <div @onclick="OpenFilePickerAsync"
                         disabled="@GetDisabledState()">
                        @ActivatorContent
                    </div>
                </CascadingValue>
            </CascadingValue>
        }
        @if (SelectedTemplate != null)
        {
            @SelectedTemplate(_filesState.Value)
        }
    </InputContent>
</MudInputControl>
